package com.example.user.myqq;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    EditText textView;
    EditText textView2;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (EditText) findViewById(R.id.text);
        textView2 = (EditText) findViewById(R.id.text2 );
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("tian",textView.getText().toString());
                Log.i("tian",textView2.getText().toString());
                String text = textView.getText().toString().trim();
                String text2 = textView2.getText().toString().trim();
                if ( !text.equals("1") || !text2.equals("1") ){
                    showToast(MainActivity.this,"输入错误请从新输入",2000);
                    textView.setText("");
                    textView2.setText("");
                }else {  final long SPLASH_LENGTH = 3000;
                    Handler handler = new Handler();
                        setContentView(R.layout.jiazai);
                        handler.postDelayed(new Runnable() {
                            public void run() {
                                Intent intent = new Intent(MainActivity.this,DengLu.class);
                                startActivity(intent);
                                finish();
                            }
                        }, SPLASH_LENGTH);
                    textView.setText("");
                    textView2.setText("");
                }
            }
        });
    }
    public static void showToast(final Activity activity, final String word, final long time){
                activity.runOnUiThread(new Runnable() {
                            public void run() {
                                    final Toast toast = Toast.makeText(activity, word, Toast.LENGTH_LONG);
                                    toast.show();
                                    Handler handler = new Handler();
                                    handler.postDelayed(new Runnable() {
                                    public void run() {
                                    toast.cancel();
                            }
                        }, time);
                    }
                });
        }
}
